import Vue from 'vue'
import App from './App.vue'
import router from './router/router';
import axios from './services/base/http'
import Vuex from 'vuex'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/public.scss';
import store from './store/index.js';
Vue.config.productionTip = false;
Vue.prototype.$axios = axios;

Vue.use(ElementUI);
Vue.use(Vuex);

router.beforeEach((to, from, next) => {
    const type = to.meta.type;
    // 判断该路由是否需要登录权限
    if (type === 'login') {
        if (JSON.parse(window.localStorage.getItem('userInfo'))) {
            next('/home')
        } else {
            next('/login')
        }
    } else {
        next()  // 确保一定要有next()被调用
    }
})

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
